layui.use('table', function () {
    var table = layui.table;

    table.render({
        elem: '#test'
        , url: '/travel/scenic/page'
        , method: 'post'
        , cellMinWidth: 80
        , toolbar: true
        , title: '景点数据'
        , totalRow: true
        , cols: [[
            {field: 'scenicId', title: 'ID', sort: true}
            , {field: 'scenicName', title: '景点名称'}
            , {field: 'scenicPic', title: '景点照片', templet: '<div><img src="{{ ctx + d.scenicPic}}"></div>'}
            , {field: 'scenicDesc', title: '景点简介'}
            , {fixed: 'right', width: 178, align: 'center', toolbar: '#barDemo'}
        ]]
        , page: true
        , response: {
            statusCode: 200 //重新规定成功的状态码为 200，table 组件默认为 0
        }
        , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
            return {
                "code": 200, //解析接口状态
                "msg": res.msg, //解析提示文本
                "count": res.data.records, //解析数据长度
                "data": res.data.rows //解析数据列表
            };
        }
    });

    table.on('tool(hotel)', function (obj) {
        var data = obj.data;
        if (obj.event === 'detail') {
            layer.open({
                type: 1,
                skin: 'layui-layer-demo', //样式类名
                closeBtn: 0, //不显示关闭按钮
                anim: 2,
                shadeClose: true, //开启遮罩关闭
                area: ['500px', '400px'],
                content: '<div style="text-align: left;margin-left: 20px"><p style="margin-bottom: 20px"> <span style="font-size: 20px">景点名称:</span>' + data.scenicName + '</p><p style="margin-bottom: 20px"><span style="font-size: 20px">景点简介:</span>' + data.scenicDesc + '</p><p style="margin-bottom: 20px"><span style="font-size: 20px">景点图片:</span><img width="100px" height="100px" src="' + ctx + data.scenicPic + '"/></p></div>'
            });
        } else if (obj.event === 'del') {
            layer.confirm('真的删除行么', function (index) {
                $.delete(ctx + "/travel/scenic/delete/" + data.scenicId, {}, function () {
                    obj.del();
                    layer.close(index);
                })
            });
        } else if (obj.event === 'edit') {
            window.location = ctx + '/travel/scenic/edit?scenicId=' + data.scenicId
        }
    });

});